<template>
  <div class="">

    <el-form ref="updateForm" :model="updateForm" :rules="updateFormRules" label-width="120px">
      <el-form-item label="加入公海原因：" prop="type">
        <el-radio-group v-model="updateForm.type" class="el_radio_group">
          <el-radio label="待联系客户5次以上跟进无法预约">待联系客户5次以上跟进无法预约</el-radio>
          <el-radio label="未成交客户3次以上无法进行成交">未成交客户3次以上无法进行成交</el-radio>
          <el-radio label="之前便是公海客户，联系完客户意向度不高">之前便是公海客户，联系完客户意向度不高</el-radio>
          <el-radio :label="1">
            <span>其他</span>
            <el-input v-model="reason" class="a_input" :readonly="updateForm.type != 1" size="small"></el-input>
          </el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="">
        <el-button type="primary" size="small" @click="saveInfo" :loading="loading">保存</el-button>
        <el-button type="default" size="small" @click="cancelEvent">取消</el-button>
      </el-form-item>
    </el-form>

  </div>
</template>
<script>
import {} from "@/http/system";
import { BATCHMARKCUSTOMERINFO } from "@/http/customer";
import { deepClone, showToast } from "@/common/util";
export default {
  name: "PublicSea",
  props: {
    ids: {
      type: Array,
      default: function () {
        return [];
      },
    },
  },
  data() {
    return {
      updateForm: {},
      updateFormRules: {
        type: [
          { required: true, message: "请选择加入公海原因", trigger: "change" },
        ],
      },
      loading: false,
      reason: "",
    };
  },
  mounted() {
    console.log(this.ids);
  },
  methods: {
    // 保存数据
    saveInfo() {
      let _this = this;
      let o = deepClone(_this.updateForm);
      let oParams = {};
      let m = this.ids;
      let arr = [];
      if (!o.type) {
        showToast({
          message: "请选择加入公海原因",
        });
        return false;
      }
      if (o.type == 1 && !this.reason) {
        showToast({
          message: "请填写其他的理由",
        });
        return false;
      }
      m.map((k) => arr.push(k.id));
      oParams.clueIds = arr;
      oParams.markTag = 5;
      oParams.markRemark = o.type;
      if (o.type == 1) {
        oParams.markRemark = `其他：${this.reason}`;
      }
      console.log(oParams);
      _this.loading = true;
      BATCHMARKCUSTOMERINFO(oParams)
        .then((res) => {
          _this.loading = false;
          if (res.code == 200) {
            showToast({
              message: "保存成功",
              type: "success",
            });
            _this.$emit("change", { id: "publicDialog", action: true });
          }
        })
        .catch((error) => {
          _this.loading = false;
        });
    },

    // 取消
    cancelEvent() {
      this.$emit("change", { id: "publicDialog" });
    },
  },
};
</script>
<style lang="scss" scoped>
.title {
  font-size: 14px;
  margin: 0 0 20px 0;
  .cred {
    color: #f00;
  }
}
.a_select {
  width: 300px;
}
.el_radio_group {
  .el-radio {
    display: block;
    margin: 10px 0 15px 0;
    .a_input {
      margin-left: 10px;
    }
  }
}
</style>